﻿
; (function (window, undefined, $) {
    var submiting = false;
    $('#frmEdit').validator({
        rules: {
            // 自定义规则，如果通过返回true，否则返回错误消息
            //cusidcard: function (element, param, field) {
            //    var idtype = $("#Id").val();
            //    if (idtype == param[0]) {
            //        return /^.+$/.test($(element).val()) || "必填项";
            //    }
            //    return true;
            //}
        },
        fields: {
            '#Name': 'required',
            //'#UpperID': 'required',
            '#Code': 'required',
            '#Sequence': 'required',
            //'#URL': 'required',
            //'#Status': 'required',
            //'#NameE': 'required',
            //'#Target': 'required',
        },
        valid: function (form) {
            if (submiting) {
                return;
            }
            submiting = true;
            FormSubmit(form, function (res) {
                if (res.Status > 0) {
                    alert("操作成功！");
                    window.location.href = "/Admin/Role";

                }
                else {
                    alert(res.Message);
                }
                submiting = false;
            })
        }
    });


    $("#btnSave").click(function (e) {
        $("#frmEdit").submit();
    });
    $("#btnReturn").click(function (e) {
        window.location.href = "/Admin/Role";
    });
    $("#btnClose").click(function (e) {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });
    util.GetParentName = function (id) {
        $.layer({
            type: 2,
            shade: [0],
            fix: false,
            title: '菜单详情',
            maxmin: false,
            iframe: { src: options.MenuTreeUrl },
            area: ['200px', '440px'],
            close: function (index) {
                //子窗口返回值 layer.getChildFrame('#name', index).val()
                //layer.msg('您获得了子窗口标记：' + layer.getChildFrame('#name', index).val(), 3, 1);
            }
            //end: function (index) {
            //    $('#lbParentName').html($('#UpperID').val());
            //}
        });

    };
    util.GetRates = function (id, num) {
        num = num.replace(/[^0-9|\.]/g, '');
        if (num > 1) {
            num = 1;
        }
        $('#' + id).val(num);
    }

    util.GetNum = function (id, num) {
        num = num.replace(/[^0-9|\.]/g, '');
        $('#' + id).val(num);
    }

    util.getFloatStr = function (id, num) {
        num = num.replace(/[^0-9|\.]/g, ''); //清除字符串中的非数字非.字符
        var no = changeTwoDecimal(parseFloat(num));
        if (!no) {
            $('#' + id).val('');
        }
        else {
            $('#' + id).val(no.toFixed(2));
        }
    };

    function changeTwoDecimal(x) {
        if (isNaN(x)) {
            return false;
        }
        f_x = Math.round(x * 100) / 100;
        return f_x;
    }

})(window, undefined, jQuery);